package t.com.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import butterknife.BindView;
import butterknife.ButterKnife;
import t.com.base.BaseActivity;
import t.com.been.MessageEvent;
import t.com.presenter.BusPresenter;
import t.com.view.BusView;

public class MainActivity extends BaseActivity<BusView,BusPresenter> implements BusView {


    @BindView(R.id.btn)
    Button btn;
    @BindView(R.id.te)
    TextView te;

    @Override
    protected void onCreateView(Bundle savedInstanceState) {
        setContentView(R.layout.activity_main);
    }

    @Override
    protected void initView() {
        ButterKnife.bind(this);
        EventBus.getDefault().register(this);
        te.setText("今天是星期一");

    }

    @Override
    protected void initData() {
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getBasePresenter().showBusData();
            }
        });
    }

    @Override
    public void showData() {
        Intent intent = new Intent(this,SecondActivity.class);
        startActivity(intent);
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void Event(MessageEvent messageEvent) {
        te.setText(messageEvent.getMessage());
    }

    @Override
    protected BusPresenter setPresenter() {
        return new BusPresenter();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if(EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().unregister(this);
        }
    }
}
